using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace MyMedia.iPod
{
	// List holder
	[StructLayout(LayoutKind.Sequential, Pack = 1)]
	unsafe struct Mhsd
	{
		public fixed byte Identifier[4];
		public int HeaderLength;
		public int TotalLength;
		public int Type;
		
		public void Read(BinaryReader reader)
		{
			byte[] data = reader.ReadBytes(sizeof(Mhsd));
			fixed (byte* pData = data)
			{
				this = *(Mhsd*)pData;
			}

			reader.ReadBytes(HeaderLength - sizeof(Mhsd));
		}

		public void Write(BinaryWriter writer)
		{
			byte[] data = StructUtil.GetBytes(this);
			writer.Write(data);

			// Padded zeros
			int count = HeaderLength - sizeof(Mhsd);
			for (int i = 0; i < count; i++)
				writer.Write((byte)0);
		}
	}
}
